import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 逆袭人生
 * Date: 2024-08-15
 * Time: 10:21
 */
public class homework1 {
    //获取一个数二进制序列中所有的偶数位和奇数位，分别输出二进制序列。
    public static void main(String[] args) {


    }
    //写一个函数返回参数二进制中1的个数
    public static void main11(String[] args) {
        int n =15;
        int count = 0;
        while (n != 0) {
            count++;
            n = n & (n - 1);
        }
        System.out.println(count);
    }
    //水仙花数
    public static void main10(String[] args) {
        //153 = 1^3 + 5^3 + 3^3
        for (int i = 0; i < 999999; i++) {
            int count = 0;//计算当前i 有几位数
            int tmp = i;
            while (tmp != 0) {
                count++;
                tmp = tmp / 10;
            }
            //count的值  是多少已经计算完成的 i还是没有变的
            //计算i[tmp]的每一位
            tmp = i;
            int sum = 0;
            while (tmp != 0) {
                sum += Math.pow(tmp % 10,count);
                tmp = tmp /10;
            }
            if (sum == i) {
                System.out.println(i);
            }
        }




    }
    //打印乘法口诀表
    public static void main9(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= i; j++) {
                System.out.print(i + "*" + j + "=" + i*j + " ");
            }
            System.out.println();
        }
    }
    //模拟登陆
    public static void main8(String[] args) {
        Scanner in = new Scanner(System.in);
        int count = 3;
        while (count != 0) {
            System.out.println("请输入你的密码："+ "你还有" + count + " 次机会！");
            String password = in.nextLine();
            if (password.equals("1234")) {
                System.out.println("登录成功");
                break;
            } else {
                System.out.println("密码错误");
                count--;
            }
        }
    }
    //打印 X 图形
    public static void main7(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int a = in.nextInt();
            for (int i = 0;i < a;i++) {
                for (int j = 0;j < a;j++) {
                    if (i == j ||(i + j) == a - 1 ) {
                        System.out.print("*");
                    } else{
                        System.out.print(" ");
                    }
                }
                System.out.println();//换行
            }
        }
    }
    //计算1/1-1/2+1/3-1/4+1/5 …… + 1/99 - 1/100 的值
    public static void main6(String[] args) {
        double sum = 0;
        int flg = 1;
        for (int i = 1; i <= 100; i++) {
            sum += 1.0 / i * flg;//类型的提升
            flg = -flg;
        }
        System.out.println(sum);
    }
    public static void main5(String[] args) {
        //求两个整数的最大公约数
        //辗转相除法
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int c = a % b;
        while (c != 0) {
            a = b;
            b = c;
            c = a % b;
        }
        System.out.println(c);
    }
    //优化方法2
    //开根号
    public static void main4(String[] args) {
        Scanner  scanner = new Scanner(System.in);
        int n = scanner.nextInt();

        for (int j = 1; j <= n; j++) {
            int i = 2;//若定义在for循环里面i只能成为局部变量
            for (; i <= Math.sqrt(j); i++) {
                if (j % i == 0) {
                    //System.out.println(j + "不是素数");
                    break;
                }
            }
            if (i > Math.sqrt(j)) {
                System.out.println(j + "是素数");
            }
        }
    }

    public static void main3(String[] args) {
        //优化判断素数的区间
        //优化方法1
        Scanner  scanner = new Scanner(System.in);
        int n = scanner.nextInt();

        for (int j = 1; j <= n; j++) {
            int i = 2;//若定义在for循环里面i只能成为局部变量
            for (; i <= j / 2; i++) {
                if (j % i == 0) {
                    //System.out.println(j + "不是素数");
                    break;
                }
            }
            if (i > j / 2) {
                System.out.println(j + "是素数");
            }

        }

    }
    public static void main2(String[] args) {
        //判断是否是素数
        Scanner  scanner = new Scanner(System.in);
        int n = scanner.nextInt();

        for (int j = 1; j <= n; j++) {
            int i = 2;//若定义在for循环里面i只能成为局部变量
            for (; i < j; i++) {
                if (j % i == 0) {
                    //System.out.println(j + "不是素数");
                    break;
                }
            }
            if (i == j) {
                System.out.println(j + "是素数");
            }

        }

    }
    public static void main1(String[] args) {
        //编写程序数一下 1到 100 的所有整数中出现多少个数字9
        //老师代码
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();//100
        int count = 0;
        for (int i = 1; i <= n; i++) {
            if (i / 10 == 9){
                count++;
            } else if (i % 10 == 9) {
                count++;
            }
        }
        System.out.println(count);
    }
}
